package org.xs.object.dao.product;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.xs.object.utils.R;

import java.time.LocalDateTime;
import java.util.List;

@Repository
public interface ProductRepository extends JpaRepository<Product, Integer> {
    //Product findByProductName(String productName);
    //更新商品
    @Modifying
    @Query(value = "update product set product_name = ?1,money=?2,brand = ?3,logo_url = ?4,operation = ?5,update_time=?6 where id = ?7",nativeQuery = true)
    void updateProduct(String productName, Integer money,String brand, String logo_url, String operation, LocalDateTime update_time, Integer id);

    @Query(value = "select * from product where product_name = ?1",nativeQuery = true)
    List<Product> findByProductName(String name);

    @Query(value = "select * from product where brand = ?1",nativeQuery = true)
    List<Product> findByBrand(String brand);

    @Modifying
    @Query(value = "update product set logo_url = null where id = ?1",nativeQuery = true)
    void deleteLogoUrlById(Integer id);
}
